﻿#include "msgprocess.h"
#include <QStringBuilder>
#include <QDebug>
#include <QDateTime>

MsgProcess::MsgProcess(QThread *parent) :QThread(parent)
{
    m_isExit = true;

    m_userInedx = 0;
    m_userImageInedx = 0;
    m_userImageCount = 0;

    m_reserveInedx = 0;                 /// ReserveList    ReserveImageList
    m_hotelInedx = 0;                         /// HotelInfoList     HotelListImage
    m_saveInedx = 0;                          /// SaveList    SaveHotelImage

    m_hotelImageInedx = 0;                /// HotelDetailImage
    m_hotelImageCount = 0;                /// HotelDetailImage --- 获取->比较

    m_houseInedx = 0;                         /// HouseList
    m_sendImageIndex = 0;               /// HouseImage
    m_houseImageInedx = 0;             /// HouseImage*

    m_commentInedx = 0;                   /// CommentList
    m_commentImageInedx = 0;      /// CommentImage  一个评论的图片的index
    m_commentImageCount = 0;      /// CommentImage  已经发送评论个数  与
                                                           ///评论总数glovar的list.size() 总数比较判断是否结束

    m_hotelManageIndex = 0;           /// HotelManageList
}

void MsgProcess::exitThread(void)
{
    m_isExit = false;
}

void MsgProcess::run(void)
{
    while (m_isExit)
    {
        //取出消息队列中的命令进行解析
        if (!GlobalVars::g_msgQueue.isEmpty())//消息队列非空
        {
            QString msg = GlobalVars::g_msgQueue.dequeue();
            parseUserAsk(msg);
        }
        msleep(20);
        if (!GlobalVars::g_ImageMsgQueue.isEmpty())
        {
            ImageMsgMap imageMap = GlobalVars::g_ImageMsgQueue.dequeue();
            parseUserAsk(imageMap);
        }
        msleep(20);
    }
}

/**
 * @brief MsgProcess::parseUserAsk
 * @param msg
 * @作用: 解析msg
 */
void MsgProcess::parseUserAsk(QString msg)
{
    QStringList list = msg.split("#");
    int cmd = msg.at(0).toLatin1();
//    qDebug() << "cmd = " << cmd;
    switch (cmd)
    {
        ///通用请求命令
        case CMD_UserRegister_R: parseUserRegister(list.at(1)); break;
        case CMD_UserInfo_I: parseUserInfos(list.at(1)); break;
        case CMD_HeadPic_i: parseHeadPic(list.at(1)); break;
        case CMD_ModifyPswd_P: parseModifyPassword(list.at(1)); break;
        case CMD_UpdateUserInfo_U: parseModifyUserInfos(list.at(1)); break;

        case CMD_HotelSearch_S: parseGainHotelInfoList(list.at(1)); break;
        case CMD_HotelSearchNext_N: SendHotelInfoListOneByOne(list.at(1)); break;
        case CMD_HotelImageDetail_t: parseHotelDetailImage(list.at(1)); break;
        case CMD_HotelImageSearch_M: parseHotelImage(QString(CMD_HotelImageSearch_M),list.at(1)); break;

        case CMD_HouseList_H: parseGetHouseList(list.at(1)); break;
        case CMD_HouseImage_T: parseHouseImage(list.at(1)); break;

        case CMD_SubmitReserve_D: parseReserveSubmit(list.at(1)); break;
        case CMD_ReserveList_d: parseGainReserveList(list.at(1)); break;
        case CMD_ReserveDelete_l: parseReserveDelete(list.at(1)); break;
        case CMD_ReserveDetails_a: parseGainReserveDetails(list.at(1)); break;
        case CMD_HotelImageOrder_o: parseReserveHotelImage(list.at(1)); break;

        case CMD_SubmitComment_p: parseCommentSubmit(list.at(1)); break;
        case CMD_CommentList_A: parseGainCommentList(list.at(1)); break;
        case CMD_CommentImage_E: parseGainCommentImage(list.at(1)); break;

        case CMD_SaveList_s: parseGainSaveList(list.at(1)); break;
        case CMD_DeleteSave_B: parseDeleteSave(list.at(1)); break;
        case CMD_SubmitSave_c: parseSubmitSave(list.at(1)); break;
        case CMD_HotelImageSave_v: parseSaveHotelImage(list.at(1)); break;
        case CMD_HotelDetailsByID_B: parseGainHotelDetailsByID(list.at(1)); break;


        ///////////////////////////////// business ////////////////////////////////
        case CMD_HotelManageIdAndName_V: parseGainHotelManageIdAndName(list.at(1)); break;
        case CMD_HotelManageList_Z: parseGainHotelManageList(list.at(1)); break;
        case CMD_HotelManageImage_z: parseHotelManageImage(list.at(1)); break;
        case CMD_DeleteHotel_Y: parseDeleteHotel(list.at(1)); break;
        case CMD_DeleteHouse_y: parseDeleteHouse(list.at(1)); break;
        case CMD_SubmitHotel_W: parseSubmitHotel(list.at(1)); break;
        case CMD_SubmitHouse_w: parseSubmitHouse(list.at(1)); break;
        case CMD_OrderManageList_x: parseGainOrderManageList(list.at(1)); break;
        case CMD_ModifyOrderState_u: parseModifyOrderState(list.at(1)); break;
        case CMD_SubmitBusComment_r: parseSubmitBusComment(list.at(1)); break;


        ///////////////////////////////// worker ////////////////////////////////
        case CMD_UserCert_O: parseGainUserCertList(list.at(1)); break;
        case CMD_UserCertImage_K: parseGainUserCertImage(list.at(1)); break;
        case CMD_UserCertResult_J: parseUserCertResult(list.at(1)); break;
        case CMD_HotelCertResult_K: parseHotelCertResult(list.at(1)); break;
        default:        qDebug() << "msg--- "; break;
    }
}

void MsgProcess::parseUserAsk(ImageMsgMap msg)//id + item + image
{
    QStringList strList = msg.keys();
    QStringList stringList = strList.at(0).split("#");
    int cmd = stringList.at(0).at(0).toLatin1();

    qDebug() << "msg = " << msg;
    qDebug() << "cmd = " << cmd;
    qDebug() << "strList = " << strList;
    qDebug() << "stringList = " << stringList;
    qDebug() << "image.size " << msg.value(strList.at(0)).width() << msg.value(strList.at(0)).height();

    switch (cmd)
    {
        case CMD_UploadHeadPic_j:
                parseUploadHeadPic(stringList.at(1),msg.value(strList.at(0))); break;; break;///上传头像
        case CMD_BusinessCertificate_C:///上传实名认证图片
                parseBusinessManCertificate(stringList.at(1),msg.value(strList.at(0))); break;
        case CMD_SubmitCommentImage_m:///上传评论图片
                parseSubmitCommentImage(stringList.at(1),msg.value(strList.at(0))); break;
        case CMD_SubmitHouseImage_q:///上传房间图片
                parseSubmitHouseImage(stringList.at(1),msg.value(strList.at(0))); break;
        case CMD_SubmitHotelImage_Q:///上传酒店图片
                parseSubmitHotelImage(stringList.at(1),msg.value(strList.at(0))); break;
        default: qDebug() <<"error" ;      break;
    }
}

void MsgProcess::parseUserRegister(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    if (GlobalVars::g_userInfoMap.contains(userID))
    {
        QString msg = QString(CMD_UserRegister_R)
                % QString("#?|") % userID
                % "|该用户名已注册";
        emit signalSendMsgToClient(userID, msg);
    }else
    {
        UserInfo userInfo (list.at(0),list.at(1),list.at(2),list.at(3),list.at(4),list.at(6),list.at(5));
        userInfo.setHeadPic("F:/ForWork/HotelPlatform/image/head_pic/avatar/noHeadPic.jpg");
        ExecSQL::addNewUserInfo(userInfo);
        ExecSQL::searchAllUserInfos();
        QString msg = QString(CMD_UserRegister_R)
                % QString("#!|") % userID
                % "|注册成功";
        emit signalSendMsgToClient(userID, msg);
    }
}

void MsgProcess::parseUserInfos(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString role = list.at(1);
    if (GlobalVars::g_userInfoMap.contains(userID))
    {
        UserInfoList::iterator iter =  GlobalVars::g_userInfoMap[userID];
        msg = QString(CMD_UserInfo_I)
                % QString("#!|") % userID
                % "|"% iter->getName()
                % "|"% iter->getSex()
                % "|"% iter->getBirthday()
                % "|"% iter->getPhone()
                % "|"% iter->getEmail()
                % "|"% iter->getRealName()
                % "|"% iter->getCertificate();

        emit signalSendMsgToClient(userID, msg);
    }
    else{
        msg = QString(CMD_UserInfo_I)
                % QString("#?|") % userID
                % "|未找到该用户";
        emit signalSendMsgToClient(userID, msg);
    }
}

void MsgProcess::parseModifyPassword(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString oldPwd = list.at(1);
    QString newPwd = list.at(2);
    if (GlobalVars::g_userInfoMap.contains(userID))
    {
        UserInfoList::iterator iter =  GlobalVars::g_userInfoMap[userID];
        if (oldPwd == iter->getPassword())
        {
            if (ExecSQL::modifyUserInfoForPswd(userID,newPwd))
            {
                ExecSQL::searchAllUserInfos();
                msg = QString(CMD_ModifyPswd_P)
                        % QString("#!|") % userID
                        % "|修改成功，重新登录!!!";
            }
        }else
        {
            msg = QString(CMD_ModifyPswd_P)
                    % QString("#?|") % userID
                    % "|密码不正确";
        }
    }
    else{
        msg = QString(CMD_ModifyPswd_P)
                % QString("#?|") % userID
                % "|未找到该用户";
    }
    emit signalSendMsgToClient(userID, msg);
}

void MsgProcess::parseModifyUserInfos(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString name = list.at(1);
    QString sex = list.at(2);
    QString birth = list.at(3);
    QString phone = list.at(4);
    QString email = list.at(5);
    if (GlobalVars::g_userInfoMap.contains(userID))
    {
        UserInfoList::iterator iter =  GlobalVars::g_userInfoMap[userID];
        if (!name.isEmpty())
        {
            ExecSQL::modifyUserInfoForName(userID,name);
        }
        if (!sex.isEmpty())
        {
            ExecSQL::modifyUserInfoForSex(userID,sex);
        }
        if (!birth.isEmpty())
        {
            ExecSQL::modifyUserInfoForBirthday(userID,birth);
        }
        if (!phone.isEmpty())
        {
            ExecSQL::modifyUserInfoForPhone(userID,phone);
        }
        if (!email.isEmpty())
        {
            ExecSQL::modifyUserInfoForEmail(userID,email);
        }
        ExecSQL::searchAllUserInfos();
        msg = QString(CMD_ModifyPswd_P)
                % QString("#!|") % userID
                % "|修改成功";
    }
    else{
        msg = QString(CMD_ModifyPswd_P)
                % QString("#?|") % userID
                % "|未找到该用户";
    }
    emit signalSendMsgToClient(userID, msg);
}

void MsgProcess::parseHeadPic(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    ExecSQL::searchAllUserInfos();

    if (GlobalVars::g_userInfoMap.contains(userID))
    {
        UserInfoList::iterator iter =  GlobalVars::g_userInfoMap[userID];
        msg = QString(CMD_HeadPic_i)
                % QString("#!|") % userID;
        emit signalSendImageToClient(userID, msg, iter->getHeadPic());
    }
}
void MsgProcess::parseUploadHeadPic(const QString& msg, const QImage& image)
{
    QStringList valueList = msg.split("|");
    QString userID = valueList.at(0);

    QString msgSend = QString(CMD_UploadHeadPic_j)
            % QString("#!|成功");
    emit signalSendMsgToClient(userID,msgSend);
    emit signalSaveUserHeadImage(userID,image);
    emit signalShowImage(image);
}

/// 实名认证 -- 接收到图片
void MsgProcess::parseBusinessManCertificate(const QString& msg, const QImage& image)
{
    QStringList valueList = msg.split("|");
    QString userID = valueList.at(0);
    QString realName;
    int totalCount;
    int currentIndex;
    if (valueList.size() == 3)
    {
        totalCount = valueList.at(1).toInt();
        currentIndex = valueList.at(2).toInt();
    }
    else
    {
        realName = valueList.at(1);
        totalCount = valueList.at(2).toInt();
        currentIndex = valueList.at(3).toInt();
    }

    ExecSQL::searchAllUserInfos();
    if (GlobalVars::g_userInfoMap.contains(userID))
    {
        QString message = QString(CMD_BusinessCertificate_C)
                % QString("#!|") % "成功";
        ExecSQL::modifyUserInfoForCertState(userID,"正在审核");

        if (currentIndex == 0)
        {
            ExecSQL::modifyUserInfoForRealName(userID,realName);
        }
        emit signalSendMsgToClient(userID,message);
        emit signalSaveUserCertImage(userID,image);
        emit signalShowImage(image);

        if (totalCount == currentIndex+1)
        {
             emit signalUploadPicSuccessed();
        }
    }
}

///  接收到评论图片
void MsgProcess::parseSubmitCommentImage(const QString& msg, const QImage& image)
{
    QStringList valueList = msg.split("|");
    QString userID = valueList.at(0);
    QString reserveID = valueList.at(1);
    QString commentID = valueList.at(2);
    QString msgSend = QString(CMD_SubmitCommentImage_m)
            % QString("#!|成功");

    ExecSQL::modifyCommentInfoForPhoto(reserveID,"有图片");

    emit signalSendMsgToClient(userID,msgSend);
    emit signalSaveCommentImage(commentID,image);
    emit signalShowImage(image);
}

void MsgProcess::parseGainHotelInfoList(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QVector< QVector<QString> > doubleArray;

    for (int i = 1; i < list.size(); i++)
    {
        QStringList strList = list.at(i).split("/");
        QVector<QString> vec;
        if (strList.at(1).isEmpty())
        {
            vec.append("");
            doubleArray.append(vec);
            continue;
        }
        vec.append(strList.at(0));
        if (strList.at(0) == QString::number(H_Type))
        {
            for(int j = 1; j < strList.size(); j++)
            {
                vec.append(strList.at(j));
            }
        }
        else if (strList.at(0) == QString::number(H_Star))
        {
            for(int j = 1; j < strList.size(); j++)
            {
                QString str = strList.at(j).split("-").join("/");
                vec.append(str);
            }
        }
        else if (strList.at(0) == QString::number(H_Mark))
        {
            vec.append(strList.at(1));
            vec.append(strList.at(2));
        }
        else
        {
            vec.append(strList.at(1));
        }
        doubleArray.append(vec);
    }

    qDebug() << "doubleArray" << doubleArray;
    ExecSQL::searchHotelInfoForMoreCondition(doubleArray);
    m_hotelInedx = 0;

    if (GlobalVars::g_hotelInfoList->size() != 0)
    {
        SendHotelInfoListOneByOne(userID);
    }
}

void MsgProcess::SendHotelInfoListOneByOne(QString userID)
{
    if (m_hotelInedx < GlobalVars::g_hotelInfoList->size())
    {
        QString hotelId = GlobalVars::g_hotelInfoList->at(m_hotelInedx).getHotel();
        HotelInfoList::iterator iter =  GlobalVars::g_hotelInfoMap[hotelId];
        QString msg = QString(CMD_HotelSearch_S)
                % QString("#!|") % iter->getHotel()
                % "|" % iter->getName()
                % "|" % iter->getStar()
                % "|" % iter->getLocation()
                % "|" % iter->getMark()
                % "|" % QString::number(iter->getCommentCount())
                % "|" % QString::number(iter->getLowPrice())
                % "|" % iter->getServer();//获取酒店的服务--停车场/餐厅等;
        if (m_hotelInedx == 0)
        {
            msg +=("|" + QString::number(GlobalVars::g_hotelInfoList->size()));
        }
        m_hotelInedx++;
        emit signalSendMsgToClient(userID, msg);
    }
    else
    {
        m_hotelInedx = 0;
        QString msg = QString(CMD_HotelSearch_S)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendMsgToClient(userID, msg);
    }
}

/// 没有进行数据库操作，因为在获取文字列表之后随即获取图片，故没有重新数据库操作
void MsgProcess::parseHotelImage(QString cmd, QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    if (GlobalVars::g_hotelInfoList->size() == 0)
    {
        m_hotelInedx = 0;
        QString msg = cmd  % QString("#?|没有记录");
        emit signalSendImageToClient(userID, msg, "");
        return;
    }

    if (m_hotelInedx < GlobalVars::g_hotelInfoList->size())
    {
        QString hotelId = GlobalVars::g_hotelInfoList->at(m_hotelInedx).getHotel();
        HotelInfoList::iterator iter =  GlobalVars::g_hotelInfoMap[hotelId];
        QString msg = cmd % QString("#!|") % hotelId;                               /// 其他请求图片只请求一张

        QStringList pathList = iter->getPhoto().split("#");
        if (pathList.size() < 2)/// 数据库中数据错误 -- 导致没有图片
        {
            emit signalSendImageToClient(userID, msg, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
        }
        else
        {
            emit signalSendImageToClient(userID, msg, pathList.at(0)+"\\"+pathList.at(1));
        }
        m_hotelInedx++;
    }
    else
    {
        m_hotelInedx = 0;
        QString msg = cmd  % QString("#?|没有下一条记录");
        emit signalSendImageToClient(userID, msg,"");
    }
}

void MsgProcess::parseHotelDetailImage(QString msg)/// 酒店详情请求图片会请求多张
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);

    if (list.at(2) == "0")
    {
        m_hotelImageInedx = 0;
        ExecSQL::searchHotelInfoForNumber(hotelID);

        if (GlobalVars::g_hotelInfoList->size() == 0)
        {
            QString msg = QString(CMD_HotelImageDetail_t)  % QString("#?|没有记录");
            emit signalSendImageToClient(userID, msg, "");
            return;
        }

        HotelInfoList::iterator iter =  GlobalVars::g_hotelInfoMap[hotelID];
        QStringList pathList = iter->getPhoto().split("#");                             /// 酒店的所有图片
        m_hotelImageCount = pathList.size();
    }

    if (m_hotelImageInedx < m_hotelImageCount)
    {
        HotelInfoList::iterator iter =  GlobalVars::g_hotelInfoMap[hotelID];
        if (m_hotelImageInedx == 0)
        {
            QString imagePath = iter->getBusinessLicense();
            QString message = QString(CMD_HotelCredImage_e) % QString("#!|成功");
            if (imagePath.isEmpty())
            {
                emit signalSendImageToClient(userID, message, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
            }
            else
            {
                emit signalSendImageToClient(userID, message, imagePath);
            }
        }
        else
        {
            QString message = QString(CMD_HotelImageDetail_t) % QString("#!|成功");
            QStringList pathList = iter->getPhoto().split("#");                             /// 酒店的所有图片
            if (pathList.size() < 2)/// 数据库中数据错误 -- 导致没有图片
            {
                emit signalSendImageToClient(userID, message, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
            }
            else
            {
                emit signalSendImageToClient(userID, message, pathList.at(0)+"\\"+pathList.at(m_hotelImageInedx));
            }
        }

        m_hotelImageInedx++;
    }
    else
    {
        QString message = QString(CMD_HotelImageDetail_t) % QString("#?|没有下一个记录");
        emit signalSendImageToClient(userID, message, "");
    }
}

void MsgProcess::parseGetHouseList(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);

    if (list.at(2) == "0")
    {
        m_houseInedx = 0;
        ExecSQL::searchHouseInfosForHotel(hotelID);
        if (GlobalVars::g_houseInfoList->size() == 0)
        {
            msg = QString(CMD_HouseList_H)
                    % QString("#?|没有记录");
            emit signalSendMsgToClient(userID, msg);
        }
        else{
            SendHouseListOneByOne(userID);
        }
    }
    else
    {
         SendHouseListOneByOne(userID);
    }
}
void MsgProcess::SendHouseListOneByOne(QString userID)
{
    if (m_houseInedx < GlobalVars::g_houseInfoList->size())
    {
        /// userID houseID type area bedType window price capacity bathroom Acc
        QString houseId = GlobalVars::g_houseInfoList->at(m_houseInedx).getHouse();
        HouseInfoList::iterator iter =  GlobalVars::g_houseInfoMap[houseId];
        QString msg = QString(CMD_HouseList_H)
                % QString("#!|") % iter->getHouse()
                % "|" % iter->getType()
                % "|" % iter->getArea()
                % "|" % iter->getBedType()
                % "|" % iter->getWindow()
                % "|" % QString::number(iter->getPrice())
                % "|" % QString::number(iter->getCapacity())
                % "|" % iter->getBathroom()
                % "|" % iter->getBathroomAcc()
                % "|" % iter->getNet()
                % "|" % iter->getBreakfast()
                % "|" % iter->getMedia()
                % "|" % QString::number(iter->getCount());
        m_houseInedx++;
        emit signalSendMsgToClient(userID, msg);
    }
    else
    {
        m_houseInedx = 0;
        QString msg = QString(CMD_HouseList_H)
                % QString("#?|没有下一条记录");
        emit signalSendMsgToClient(userID, msg);
    }
}

/// type count image
void MsgProcess::parseHouseImage(QString userID)
{
    /// 所有的房间类型数 ---  g_houseInfoList->size()
    /// 每个类型房间的照片数  ---  pathList.size()
//    qDebug() << "1" << houseImageInedx << GlobalVars::g_houseInfoList->size();
    if (m_houseImageInedx < GlobalVars::g_houseInfoList->size())
    {
        QString houseID = GlobalVars::g_houseInfoList->at(m_houseImageInedx).getHouse();
        HouseInfoList::iterator iter =  GlobalVars::g_houseInfoMap[houseID];
        QString msg = QString(CMD_HouseImage_T)
                % QString("#!|")  % iter->getType();

        /// m_pathList为0，重新装载 图片路径的list
        if (m_pathList.size() == 0)
        {
            QStringList photoList =  iter->getPhoto().split("#");
            if (photoList.size() < 2)/// 数据库中数据错误 -- 导致没有图片
            {
                m_houseImageInedx++;
                m_sendImageIndex = 0;
                msg = QString(CMD_HouseImage_T)
                                % QString("#!|error");
                emit signalSendImageToClient(userID, msg, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
                return;
            }
            for (int i = 1; i < photoList.size(); i++)
            {
                m_pathList.append(photoList.at(0) + "\\" + photoList.at(i));
            }
        }

        if (m_sendImageIndex < m_pathList.size())
        {
            QString path =m_pathList.at(m_sendImageIndex);

            if (m_sendImageIndex == m_pathList.size()-1)
            {
                m_sendImageIndex = 0;
                m_pathList.clear();
                m_houseImageInedx++;
            }else
            {
                m_sendImageIndex++;
            }

            emit signalSendImageToClient(userID, msg, path);
        }
        else
        {
            m_sendImageIndex = 0;
            m_houseImageInedx++;

            msg = QString(CMD_HouseImage_T)
                            % QString("#!|error");
            emit signalSendImageToClient(userID, msg, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
        }
    }
    else
    {
        m_houseImageInedx = 0;
        m_sendImageIndex = 0;
        QString msg = QString(CMD_HouseImage_T)
                % QString("#?|没有下一条记录");
        emit signalSendImageToClient(userID, msg, "");
    }
}

///////////////////////////////////////////// reserve ///////////////////////////////////////////////////
/// cmd#userID|reserveID|hotelID|hotelName|hotelLocation|hotelPhone|state
/// |houseType|reserveTime|checkInTime|checkOutTime|payment|checkInName
/// |checkInTel|arrivalTime|houseCount
void MsgProcess::parseReserveSubmit(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString reserveID = list.at(1);
    QString hotelID = list.at(2);
    QString hotelName = list.at(3);
    QString hotelLocation = list.at(4);
    QString hotelPhone = list.at(5);
    QString state = list.at(6);
    QString houseType = list.at(7);
    QString reserveTime = list.at(8);
    QString checkInTime = list.at(9);
    QString checkOutTime = list.at(10);
    int payment = list.at(11).toInt();
    QString checkInName = list.at(12);
    QString checkInTel = list.at(13);
    QString arrivalTime = list.at(14);
    int houseCount = list.at(15).toInt();
    ExecSQL::searchAllReserveInfos();

    if (GlobalVars::g_reserveInfoMap.contains(reserveID))
    {
        msg = QString(CMD_SubmitReserve_D)
                % QString("#?|") % "错误，请稍后重试";
        emit signalSendMsgToClient(userID, msg);
    }else
    {
        ReserveInfo reserveInfo (payment,houseCount,reserveID,userID, hotelID,houseType,
                                reserveTime,checkInTel,checkInName,checkInTime, checkOutTime,
                                 arrivalTime,state,hotelName,hotelLocation,hotelPhone);
        if (ExecSQL::addNewReserveInfo(reserveInfo))
        {
            ExecSQL::searchAllReserveInfos();
            msg = QString(CMD_SubmitReserve_D)
                    % QString("#!|") % "提交成功,请付款";
        }
        else
        {
            qDebug() << "error";
            msg = QString(CMD_SubmitReserve_D)
                    % QString("#?|") % "错误，请稍后重试";
        }

        emit signalSendMsgToClient(userID, msg);
    }
}

void MsgProcess::parseGainReserveList(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    qDebug() << list.at(1) ;
    if (list.at(1) == "0")
    {
        ExecSQL::searchReserveInfosForUser(userID);
        ExecSQL::searchAllHotelInfos();
        m_reserveInedx = 0;
        if (GlobalVars::g_reserveInfoList->size() == 0)
        {
            msg = QString(CMD_ReserveList_d)
                    % QString("#?|") % "您还没有订单哦";
            emit signalSendMsgToClient(userID, msg);
        }else
        {
            SendReserveListOneByOne(userID);
        }
    }
    else
    {
        SendReserveListOneByOne(userID);
    }
}
void MsgProcess::SendReserveListOneByOne(QString userID)
{
    if (m_reserveInedx < GlobalVars::g_reserveInfoList->size())
    {
        /// !/? reserveID houseCount houseType checkInTime checkOutTime payment state
        QString reserveID = GlobalVars::g_reserveInfoList->at(m_reserveInedx).getReserve();
        ReserveInfoList::iterator iter =  GlobalVars::g_reserveInfoMap[reserveID];
        QString msg = QString(CMD_ReserveList_d)
                % QString("#!|") % iter->getReserve()
                % "|" % iter->getHotelName()
                % "|" % QString::number(iter->getHouseCount())
                % "|" % iter->getHouseType()
                % "|" % iter->getCheckInTime()
                % "|" % iter->getCheckOutTime()
                % "|" % QString::number(iter->getPayment())
                % "|" % iter->getState()
                % "|" % iter->getHotel()
                % "|" % iter->getCommentState();

        m_reserveInedx++;
        emit signalSendMsgToClient(userID, msg);
    }
    else
    {
        m_reserveInedx = 0;
        QString msg = QString(CMD_ReserveList_d)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendMsgToClient(userID, msg);
    }
}

void MsgProcess::parseReserveHotelImage(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    if (list.at(1) == "0")                                                              /// 获取整个收藏的个数、列表
    {
         m_reserveInedx = 0;
         SendReserveImageListOneByOne(userID);                            /// 将收藏的列表逐个发送 --- 请求一次发一次
    }
    else
    {
        SendReserveImageListOneByOne(userID);
    }
}
void MsgProcess::SendReserveImageListOneByOne(QString userID)
{
    if (m_reserveInedx < GlobalVars::g_reserveInfoList->size())
    {
        /// !/? reserveID image
        QString reserveID = GlobalVars::g_reserveInfoList->at(m_reserveInedx).getReserve();
        if (GlobalVars::g_reserveInfoMap.contains(reserveID))
        {
            ReserveInfoList::iterator iter =  GlobalVars::g_reserveInfoMap[reserveID];
            if (GlobalVars::g_hotelInfoMap.contains(iter->getHotel()))
            {
                HotelInfoList::iterator iterat =  GlobalVars::g_hotelInfoMap[iter->getHotel()];
                QString msg = QString(CMD_HotelImageOrder_o)
                        % QString("#!|") % reserveID;

                m_reserveInedx++;
                QStringList images = iterat->getPhoto().split("#");
                if (images.size() < 2)/// 数据库中数据错误 -- 导致没有图片
                {
                    emit signalSendImageToClient(userID, msg, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
                }
                else
                {
                    emit signalSendImageToClient(userID, msg, images.at(0)+"\\"+images.at(1));
                }
            }
        }
    }
    else
    {
        QString msg = QString(CMD_HotelImageOrder_o)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendImageToClient(userID, msg, "");
    }
}

void MsgProcess::parseGainReserveDetails(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString reserveID = list.at(1);

    /// reserveID hotelID houseType InName InTel InTime OutTime ReserveTime
    /// Payment ReserveHouseCount ReserveState CommentState HotelName HotelPhone HotelLocation
    ExecSQL::searchReserveInfosForID(reserveID);
    if (GlobalVars::g_reserveInfoMap.contains(reserveID))
    {
        ReserveInfoList::iterator iter =  GlobalVars::g_reserveInfoMap[reserveID];
        ExecSQL::searchAllHotelInfos();
        if (GlobalVars::g_hotelInfoMap.contains(iter->getHotel()))
        {
            HotelInfoList::iterator iterat = GlobalVars::g_hotelInfoMap[iter->getHotel()];
            msg = QString(CMD_ReserveDetails_a)
                    % QString("#!|") % iter->getReserve()
                    % "|" % iter->getHotel()
                    % "|" % iter->getHouseType()
                    % "|" % iter->getCheckInName()
                    % "|" % iter->getCheckInTel()
                    % "|" % iter->getCheckInTime()
                    % "|" % iter->getCheckOutTime()
                    % "|" % iter->getReserveTime()
                    % "|" % QString::number(iter->getPayment())
                    % "|" % QString::number(iter->getHouseCount())
                    % "|" % iter->getState()
                    % "|" % iter->getCommentState()
                    % "|" % iterat->getName()
                    % "|" % iterat->getPhone()
                    % "|" % iterat->getLocation();

            emit signalSendMsgToClient(userID, msg);
        }
    }
    else{
        msg = QString(CMD_ReserveDetails_a)
                % QString("#?|") % "请求错误";
        emit signalSendMsgToClient(userID, msg);
    }
}

void MsgProcess::parseReserveDelete(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString reserveID = list.at(1);

    ExecSQL::searchReserveInfosForID(reserveID);
    if (GlobalVars::g_reserveInfoMap.contains(reserveID))
    {
        if (ExecSQL::deleteReserveInfo(reserveID))
        {
            msg = QString(CMD_ReserveDelete_l)
                    % QString("#!|") % "删除成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else
        {
            msg = QString(CMD_ReserveDelete_l)
                    % QString("#?|") % "请求错误";
            emit signalSendMsgToClient(userID, msg);
        }
    }
    else
    {
        msg = QString(CMD_ReserveDelete_l)
                % QString("#?|") % "不存在此订单";
        emit signalSendMsgToClient(userID, msg);
    }
}

///////////////////////////////////////////// comment ///////////////////////////////////////////////////
void MsgProcess::parseCommentSubmit(QString msg)
{
    /// cmd#user|comment|star|hotel|hotelName|houseType|checkInTime|commentTime|userComment|reserveID
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString commentID = list.at(1);
    QString star = list.at(2);
    QString hotelID = list.at(3);
    QString hotelName = list.at(4);
    QString houseType = list.at(5);
    QString checkInTime = list.at(6);
    QString commentTime = list.at(7);
    QString userComment = list.at(8);
    QString reserveID = list.at(9);

    ExecSQL::searchAllCommentInfos();

    if (GlobalVars::g_commentInfoMap.contains(commentID))
    {
        msg = QString(CMD_SubmitComment_p)
                % QString("#?|") % "错误，请稍后重试";
        emit signalSendMsgToClient(userID, msg);
    }else
    {
        CommentInfo commentInfo (commentID,userID,star,hotelID, hotelName,houseType,
                                checkInTime,commentTime,userComment,reserveID);
        if (ExecSQL::addNewCommentInfo(commentInfo))
        {
            ExecSQL::searchAllCommentInfos();
            ExecSQL::modifyReserveInfoForCommentState(reserveID,"已评论");
            ExecSQL::searchAllReserveInfos();

            msg = QString(CMD_SubmitComment_p)
                    % QString("#!|") % "评论成功";
        }
        else
        {
            msg = QString(CMD_SubmitComment_p)
                    % QString("#?|") % "错误，请稍后重试";
        }

        emit signalSendMsgToClient(userID, msg);
    }
}
void MsgProcess::parseGainCommentList(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);

    if (list.at(2) == "0")                                                              /// 获取整个收藏的个数、列表
    {
        ExecSQL::searchAllUserInfos();                       /// 用户头像
        ExecSQL::searchAllHotelInfos();                      /// 酒店信息
        ExecSQL::searchCommentInfosForHotel(hotelID);
        m_commentInedx = 0;
        if (GlobalVars::g_commentInfoList->size() == 0)
        {
            msg = QString(CMD_CommentList_A)
                    % QString("#?|") % "暂时还没有评论";
            emit signalSendMsgToClient(userID, msg);
        }else                                                                                 /// 将收藏的列表逐个发送 --- 请求一次发一次
        {
            SendCommentListOneByOne(userID);
        }
    }
    else
    {
        SendCommentListOneByOne(userID);
    }
}
void MsgProcess::SendCommentListOneByOne(QString userID)
{
    if (m_commentInedx < GlobalVars::g_commentInfoList->size())
//            || commentInedx >= 5)
    {
        /// !/? commentID hotelType inTime time comment star hotelComment userName
        QString commentID = GlobalVars::g_commentInfoList->at(m_commentInedx).getComment();
        qDebug() << commentID;
        if (GlobalVars::g_commentInfoMap.contains(commentID))
        {
            CommentInfoList::iterator iter =  GlobalVars::g_commentInfoMap[commentID];
            QString msg = QString(CMD_CommentList_A)
                    % QString("#!|") % commentID
                     % "|" % iter->getHouseType()
                    % "|" % iter->getCheckInTime()
                    % "|" % iter->getCommentTime()
                    % "|" % iter->getUserComment()
                    % "|" % iter->getStar()
                    % "|" % iter->getHotelComment();

            if (GlobalVars::g_userInfoMap.contains(iter->getUser()))
            {
                UserInfoList::iterator iterat =  GlobalVars::g_userInfoMap[iter->getUser()];
                QString message = "|" % iterat->getName();

                m_commentInedx++;
                emit signalSendMsgToClient(userID, msg + message);
            }
        }
    }
    else
    {
        QString msg = QString(CMD_CommentList_A)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendMsgToClient(userID, msg);
    }
}
void MsgProcess::parseGainCommentImage(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);

    if (list.at(2) == "0")                                                              /// 获取整个评论的个数、列表
    {
        m_commentImageInedx = 0;
        m_commentImageCount = 0;          /// 已经发送的评论图片的个数
        if (GlobalVars::g_commentInfoList->size() == 0)
        {
            msg = QString(CMD_CommentImage_E)
                    % QString("#?|") % "暂时还没有评论";
            emit signalSendImageToClient(userID, msg,"");
        }else
        {
            SendCommentImageOneByOne(userID);
        }
    }
    else if (list.at(2) == "1")          /// 同一个评论的其他图片
    {
        m_commentImageInedx++;
        SendCommentImageOneByOne(userID);
    }
    else                                         /// 下一个评论的图片
    {
        m_commentImageCount++;
        m_commentImageInedx = 0;
        SendCommentImageOneByOne(userID);
    }
} ///commentImageCount
void MsgProcess::SendCommentImageOneByOne(QString userID)
{
    if (m_commentImageCount < GlobalVars::g_commentInfoList->size())
//            || commentImageInedx >= 5)
    {
            /// 获取数据库中的头像及评论图片的路径
            /// 将路径的个数放入到glovar的commentImageCount
            /// 利用commentImageIndex逐个发送
            /// 一条评论完成后commentImageIndex归零
        QString commentID = GlobalVars::g_commentInfoList->at(m_commentImageCount).getComment();
        if (GlobalVars::g_commentInfoMap.contains(commentID))
        {
            CommentInfoList::iterator iter =  GlobalVars::g_commentInfoMap[commentID];
            QString id = iter->getUser();
            if (GlobalVars::g_userInfoMap.contains(id))
            {
                UserInfoList::iterator iterat =  GlobalVars::g_userInfoMap[id];
                if (m_commentImageInedx == 0)
                {
                    QString msg = QString(CMD_CommentImage_E)
                    % QString("#!|") % commentID;
                    emit signalSendImageToClient(userID, msg,iterat->getHeadPic());
                }
                else
                {
                    QString message = QString(CMD_CommentImage_E) % QString("#!|") % commentID;
                    QStringList pathList = iter->getPhoto().split("#");                             /// 评论的所有图片

                    if (m_commentImageInedx < pathList.size())
                    {
                        if (pathList.size() < 2)/// 数据库中数据错误 -- 导致没有图片
                        {
                            m_commentImageInedx++;
                            emit signalSendImageToClient(userID, message, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
                        }
                        else
                        {
                            emit signalSendImageToClient(userID, message, pathList.at(0)+"\\"+pathList.at(m_commentImageInedx));
                        }
                    }
                    else
                    {
                        QString msg = QString(CMD_CommentImage_E)
                                % QString("#?|") % "没有下一条记录" ;
                        emit signalSendImageToClient(userID, msg,"");
                    }
                }
            }
        }
    }
    else
    {
        QString msg = QString(CMD_CommentImage_E)
                % QString("#?|") % "没有更多记录" ;
        emit signalSendImageToClient(userID, msg,"");
    }
}

///////////////////////////////////////////// save ///////////////////////////////////////////////////
void MsgProcess::parseGainSaveList(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    if (list.at(1) == "0")                                                              /// 获取整个收藏的个数、列表
    {
        ExecSQL::searchAllHotelInfos();
        ExecSQL::searchSaveInfosForUser(userID);
        m_saveInedx = 0;
        if (GlobalVars::g_saveInfoList->size() == 0)
        {
            msg = QString(CMD_SaveList_s)
                    % QString("#?|") % "您还没有收藏哦";
            emit signalSendMsgToClient(userID, msg);
        }else                                                                                 /// 将收藏的列表逐个发送 --- 请求一次发一次
        {
            SendSaveListOneByOne(userID);
        }
    }
    else
    {
        SendSaveListOneByOne(userID);
    }
}
void MsgProcess::SendSaveListOneByOne(QString userID)
{
    if (m_saveInedx < GlobalVars::g_saveInfoList->size())
    {
        /// !/? saveID hotelID hotelName mark hotelType location
        QString saveID = GlobalVars::g_saveInfoList->at(m_saveInedx).getSave();
        SaveInfoList::iterator iter =  GlobalVars::g_saveInfoMap[saveID];

        QString hotelID = iter->getHotel();
        QString msg = QString(CMD_SaveList_s)
                % QString("#!|") % saveID
                 % "|" % hotelID;

        HotelInfoList::iterator iterat =  GlobalVars::g_hotelInfoMap[hotelID];
        QString message = "|" % iterat->getName()
                % "|" % iterat->getMark()
                % "|" % iterat->getType()
                % "|" % iterat->getLocation();

        m_saveInedx++;
        emit signalSendMsgToClient(userID, msg + message);
    }
    else
    {
        QString msg = QString(CMD_SaveList_s)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendMsgToClient(userID, msg);
    }
}
void MsgProcess::parseSaveHotelImage(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    if (list.at(1) == "0")                                                              /// 获取整个收藏的个数、列表
    {
         m_saveInedx = 0;
         SendSaveImageListOneByOne(userID);                            /// 将收藏的列表逐个发送 --- 请求一次发一次
    }
    else
    {
        SendSaveImageListOneByOne(userID);
    }
}
void MsgProcess::SendSaveImageListOneByOne(QString userID)
{
    if (m_saveInedx < GlobalVars::g_saveInfoList->size())
    {
        /// !/? saveID image
        QString saveID = GlobalVars::g_saveInfoList->at(m_saveInedx).getSave();
        SaveInfoList::iterator iter =  GlobalVars::g_saveInfoMap[saveID];
        HotelInfoList::iterator iterat =  GlobalVars::g_hotelInfoMap[iter->getHotel()];
        QString msg = QString(CMD_HotelImageSave_v)
                % QString("#!|") % saveID;

        m_saveInedx++;
        QStringList images = iterat->getPhoto().split("#");
        if (images.size() < 2)/// 数据库中数据错误 -- 导致没有图片
        {
            emit signalSendImageToClient(userID, msg, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
        }
        else
        {
            emit signalSendImageToClient(userID, msg, images.at(0)+"\\"+images.at(1));
        }
    }
    else
    {
        QString msg = QString(CMD_HotelImageSave_v)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendImageToClient(userID, msg, "");
    }
}

//////////////////////////////////////////////hotel details////////////////////////////////////////////
void MsgProcess::parseGainHotelDetailsByID(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);

    ExecSQL::searchHotelInfoForNumber(hotelID);

    if (GlobalVars::g_hotelInfoMap.contains(hotelID))
    {
        HotelInfoList::iterator iter =  GlobalVars::g_hotelInfoMap[hotelID];
        ExecSQL::searchSaveInfosForUserAndHotel(userID,hotelID);
        QString save;
        if (GlobalVars::g_saveInfoList->size() == 1)
        {
            iter->setIsSave(true);
            save = "1";
        }else
        {
            save = "0";
        }

        msg = QString(CMD_HotelDetailsByID_B)
                % QString("#!|") % hotelID
                % "|"% iter->getName()
                % "|"% iter->getStar()
                % "|"% iter->getCity()
                % "|"% iter->getMark()
                % "|"% iter->getType()
                % "|"% iter->getPhone()
                % "|"% iter->getLocation()
                % "|"% iter->getOpenedTime()
                % "|"% iter->getDecoratedTime()
                % "|"% QString::number(iter->getLowPrice())
                % "|"% QString::number(iter->getHighPrice())
                % "|"% QString::number(iter->getTotalHouse())
                % "|"% QString::number(iter->getCommentCount())
                % "|" % iter->getCancellation()
                % "|" % iter->getInstruction()
                % "|" % iter->getDescription()
                % "|" % iter->getServer()//获取酒店的服务--停车场/餐厅等;
                % "|" % save;
        emit signalSendMsgToClient(userID, msg);
    }
    else{
        msg = QString(CMD_HotelDetailsByID_B)
                % QString("#?|") % "该酒店已下架";
        emit signalSendMsgToClient(userID, msg);
    }
}

void MsgProcess::parseDeleteSave(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString saveID = list.at(1);

    if (ExecSQL::deleteSaveInfo(saveID))
    {
        parseGainSaveList(userID +"|0");
    }
    else
    {
        msg = QString(CMD_DeleteSave_B)
                % QString("#?|") % "删除错误，请稍后再试";
        emit signalSendMsgToClient(userID, msg);
    }
}

void MsgProcess::parseSubmitSave(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);
    QString save = list.at(2);
    ExecSQL::searchSaveInfosForUserAndHotel(userID,hotelID);

    if (save == "1")                                            ///   添加收藏
    {
        if (GlobalVars::g_saveInfoList->size() > 0)
        {
            msg = QString(CMD_SubmitSave_c)
                    % QString("#!|") % "已存在此收藏";
            emit signalSendMsgToClient(userID, msg);
            return;
        }

        QString saveID = QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz");
        ExecSQL::searchAllSaveInfos();
        if (GlobalVars::g_saveInfoMap.contains(saveID))                                   /// saveID 冲突
        {
            msg = QString(CMD_SubmitSave_c)
                    % QString("#?|") % "收藏错误，请稍后再试";
        }
        else                                                                                                         /// 可以添加
        {
            if (!ExecSQL::addNewSaveInfo(SaveInfo(saveID,userID,hotelID)))     /// 数据库没有添加成功
            {
                msg = QString(CMD_SubmitSave_c)
                        % QString("#?|") % "收藏错误，请稍后再试";
            }
            else                                                                                                    /// 添加成功
            {
                msg = QString(CMD_SubmitSave_c)
                        % QString("#!|") % "成功收藏";
            }
        }
    }
    else                                                        ///   取消收藏
    {
        if (GlobalVars::g_saveInfoList->size() > 0)                                   /// 存在此收藏
        {
            QString saveID = GlobalVars::g_saveInfoList->at(0).getSave();
            if (!ExecSQL::deleteSaveInfo(saveID))
            {
                msg = QString(CMD_SubmitSave_c)
                        % QString("#?|") % "删除错误，请稍后再试";
            }
            else{
                msg = QString(CMD_SubmitSave_c)
                        % QString("#!|") % "删除成功";
            }
        }
        else
        {
            msg = QString(CMD_SubmitSave_c)
                    % QString("#?|") % "没有该收藏";
        }
    }

    emit signalSendMsgToClient(userID, msg);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// business ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////************ 店面 == 可管理的酒店 == HotelManageList *************////////////////
void MsgProcess::parseGainHotelManageIdAndName(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    ExecSQL::searchHotelInfoForUser(userID);
    if (GlobalVars::g_hotelInfoList->size() == 0)
    {
        msg = QString(CMD_HotelManageIdAndName_V)
                % QString("#?|0") % "您还没有店面哦";
        emit signalSendMsgToClient(userID, msg);
    }else                                                                                 /// 将店面的列表逐个发送 --- 请求一次发一次
    {
        int size = GlobalVars::g_hotelInfoList->size();
        QString message = QString(CMD_HotelManageIdAndName_V)
                % QString("#!|") % QString::number(size);
        for (int i = 0; i < size; i++)
        {
            QString hotelID = GlobalVars::g_hotelInfoList->at(i).getHotel();
            if (GlobalVars::g_hotelInfoMap.contains(hotelID))
            {
                HotelInfoList::iterator iter =  GlobalVars::g_hotelInfoMap[hotelID];
                message += ("|"  % hotelID % "|" % iter->getName() % "|" % iter->getMark()
                            % "|" % QString::number(iter->getCommentCount()) % "|" % iter->getState());
            }
        }

        emit signalSendMsgToClient(userID, message);
    }
}
void MsgProcess::parseGainHotelManageList(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    if (list.at(1) == "0")                                                           /// 获取整个店面的个数、列表
    {
        ExecSQL::searchAllUserInfos();
        if (GlobalVars::g_userInfoMap.contains(userID))
        {
            UserInfoList::iterator iter = GlobalVars::g_userInfoMap[userID];
            if (iter->getRole().toInt() == USER_Business)
            {
                ExecSQL::searchHotelInfoForUser(userID);
            }
            else
            {
                ExecSQL::searchHotelInfoForState("审核中");
            }
        }
        m_hotelManageIndex = 0;
        if (GlobalVars::g_hotelInfoList->size() == 0)
        {
            msg = QString(CMD_HotelManageList_Z)
                    % QString("#?|") % "您还没有店面哦";
            emit signalSendMsgToClient(userID, msg);
        }else                                                                                 /// 将店面的列表逐个发送 --- 请求一次发一次
        {
            sendHotelManageListOneByOne(userID);
        }
    }
    else
    {
        sendHotelManageListOneByOne(userID);
    }
}
void MsgProcess::sendHotelManageListOneByOne(QString& userID)
{
    if (m_hotelManageIndex < GlobalVars::g_hotelInfoList->size())
    {
        /// !/?  hotelID hotelName mark hotelType location
        QString hotelID = GlobalVars::g_hotelInfoList->at(m_hotelManageIndex).getHotel();
        if (GlobalVars::g_hotelInfoMap.contains(hotelID))
        {
            QString msg;
            HotelInfoList::iterator iter =  GlobalVars::g_hotelInfoMap[hotelID];
            if (GlobalVars::g_userInfoMap.contains(userID))
            {
                UserInfoList::iterator it = GlobalVars::g_userInfoMap[userID];
                if (it->getRole().toInt() == USER_Business)
                {
                    msg = QString(CMD_HotelManageList_Z)
                            % QString("#!|") % hotelID
                            % "|" % iter->getName()
                            % "|" % iter->getMark()
                            % "|" % iter->getType()
                            % "|" % iter->getLocation()
                            % "|" % iter->getState();
                }
                else
                {
                    QString realName;
                    QString phone;
                    if (GlobalVars::g_userInfoMap.contains(iter->getUser()))
                    {
                        UserInfoList::iterator it = GlobalVars::g_userInfoMap[iter->getUser()];
                        realName = it->getRealName();
                        phone = it->getPhone();
                    }
                    msg = QString(CMD_HotelManageList_Z)
                            % QString("#!|") % hotelID
                            % "|" % iter->getName()
                            % "|" % iter->getMark()
                            % "|" % iter->getType()
                            % "|" % iter->getLocation()
                            % "|" % iter->getState()
                            % "|" % iter->getStar()
                            % "|" % realName
                            % "|" % phone
                            % "|" % QString::number(iter->getLowPrice())
                            % "|" % QString::number(iter->getTotalHouse());
                }
            }

            m_hotelManageIndex++;
            emit signalSendMsgToClient(userID, msg);
        }
    }
    else
    {
        QString msg = QString(CMD_HotelManageList_Z)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendMsgToClient(userID, msg);
    }
}
void MsgProcess::parseHotelManageImage(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    if (list.at(1) == "0")                                                              /// 获取整个店面的个数、列表
    {
         m_hotelManageIndex = 0;
         SendHotelManageImageOneByOne(userID);               /// 将店面的列表逐个发送 --- 请求一次发一次
    }
    else
    {
        SendHotelManageImageOneByOne(userID);
    }
}
void MsgProcess::SendHotelManageImageOneByOne(QString& userID)
{
    if (m_hotelManageIndex < GlobalVars::g_hotelInfoList->size())
    {
        /// !/? hotelID image
        QString hotelID = GlobalVars::g_hotelInfoList->at(m_hotelManageIndex).getHotel();
        HotelInfoList::iterator iter =  GlobalVars::g_hotelInfoMap[hotelID];
        QString msg = QString(CMD_HotelManageImage_z)
                % QString("#!|") % hotelID;

        m_hotelManageIndex++;
        QStringList images = iter->getPhoto().split("#");
        if (images.size() < 2)/// 数据库中数据错误 -- 导致没有图片
        {
            emit signalSendImageToClient(userID, msg, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
        }
        else
        {
            emit signalSendImageToClient(userID, msg, images.at(0)+"\\"+images.at(1));
        }
    }
    else
    {
        QString msg = QString(CMD_HotelManageImage_z)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendImageToClient(userID, msg, "");
    }
}

void MsgProcess::parseDeleteHotel(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);

    if (ExecSQL::deleteHotelInfo(hotelID))
    {
        msg = QString(CMD_DeleteHotel_Y)
                % QString("#!|") % "删除成功";
    }
    else
    {
        msg = QString(CMD_DeleteHotel_Y)
                % QString("#?|") % "删除错误，请稍后再试";
    }
    emit signalSendMsgToClient(userID, msg);
}
void MsgProcess::parseDeleteHouse(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString houseID = list.at(1);

    if (ExecSQL::deleteHouseInfo(houseID))
    {
        msg = QString(CMD_DeleteHouse_y)
                % QString("#!|") % "删除成功";
    }
    else
    {
        msg = QString(CMD_DeleteHouse_y)
                % QString("#?|") % "删除错误，请稍后再试";
    }
    emit signalSendMsgToClient(userID, msg);
}
void MsgProcess::parseSubmitHotel(QString msg)
{
    ///user,id,name,location,star,type,city,phone, count,lowPrice,highPrice,openedTime,
    ///decoratedTime,description,cancel,introduce,Server
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);
    QString name = list.at(2);
    QString location = list.at(3);
    QString star = list.at(4);
    QString type = list.at(5);
    QString city = list.at(6);
    QString phone = list.at(7);

    int count = list.at(8).toInt();
    int lowPrice = list.at(9).toInt();
    int highPrice = list.at(10).toInt();

    QString openedTime = list.at(11);
    QString decoratedTime = list.at(12);
    QString description = list.at(13);
    QString cancel = list.at(14);
    QString introduce = list.at(15);
    QString Server = list.at(16);

    ExecSQL::searchAllHotelInfos();
    if (GlobalVars::g_hotelInfoMap.contains(hotelID))
    {
        if (count != 0)
        {
            if (!ExecSQL::modifyHotelInfoForCount(hotelID,QString::number(count)))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (lowPrice != 0)
        {
            if (!ExecSQL::modifyHotelInfoForLowPrice(hotelID,QString::number(lowPrice)))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (highPrice != 0)
        {
            if (!ExecSQL::modifyHotelInfoForHighPrice(hotelID,QString::number(highPrice)))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!name.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForName(hotelID,name))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!location.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForLocation(hotelID,location))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }

        if (!star.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForStar(hotelID,star))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!type.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForType(hotelID,type))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!city.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForCity(hotelID,city))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!phone.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForPhone(hotelID,phone))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!openedTime.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForOpenedTime(hotelID,openedTime))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }

        if (!decoratedTime.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForDecoratedTime(hotelID,decoratedTime))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!description.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForDescription(hotelID,description))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!cancel.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForCancel(hotelID,cancel))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!introduce.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForIntroduce(hotelID,introduce))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!Server.isEmpty())
        {
            if (!ExecSQL::modifyHotelInfoForServer(hotelID,Server))
            {
                msg = QString(CMD_SubmitHotel_W)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }

        msg = QString(CMD_SubmitHotel_W)
                % QString("#!|") % "修改成功";
        emit signalSendMsgToClient(userID, msg);
    }
    else
    {
        QString time = QDate::currentDate().toString("yyyy-MM-dd");
        HotelInfo hotel(hotelID,userID,name,location,star,type,city,phone, count,lowPrice,
                 highPrice,openedTime,decoratedTime,description,cancel,introduce,Server,"",
                        "","审核中*"+time);
        if (ExecSQL::addNewHotelInfo(hotel))
        {
            msg = QString(CMD_SubmitHotel_W)
                    % QString("#!|") % "添加成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else
        {
            msg = QString(CMD_SubmitHotel_W)
                    % QString("#?|") % "添加错误，未知";
            emit signalSendMsgToClient(userID, msg);
        }
    }
}
void MsgProcess::parseSubmitHouse(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString houseID = list.at(1);
    QString hotelID = list.at(2);
    QString houseType = list.at(3);
    int price = list.at(4).toInt();
    int count = list.at(5).toInt();
    QString area = list.at(6);
    int capacity = list.at(7).toInt();
    QString bedType = list.at(8);
    QString bathroom = list.at(9);

    QString net = list.at(10);
    QString window = list.at(11);
    QString breakfast = list.at(12);
    QString media = list.at(13);
    QString bathroomAcc = list.at(14);

    ExecSQL::searchAllHouseInfos();
    if (GlobalVars::g_houseInfoMap.contains(houseID))
    {
        if (price != 0)
        {
            if (!ExecSQL::modifyHouseInfoForPrice(houseID,QString::number(price)))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (count != 0)
        {
            if (!ExecSQL::modifyHouseInfoForCount(houseID,QString::number(count)))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (capacity != 0)
        {
            if (!ExecSQL::modifyHouseInfoForCapacity(houseID,QString::number(capacity)))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!houseType.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForType(houseID,houseType))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!area.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForArea(houseID,area))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }

        if (!bedType.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForBedType(houseID,bedType))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!bathroom.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForBathroom(houseID,bathroom))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!net.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForNet(houseID,net))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!window.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForWindow(houseID,window))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!breakfast.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForBreakfast(houseID,breakfast))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }

        if (!media.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForMedia(houseID,media))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        if (!bathroomAcc.isEmpty())
        {
            if (!ExecSQL::modifyHouseInfoForBathroomAcc(houseID,bathroomAcc))
            {
                msg = QString(CMD_SubmitHouse_w)
                        % QString("#?|") % "修改错误";
                emit signalSendMsgToClient(userID, msg);
                return;
            }
        }
        msg = QString(CMD_SubmitHouse_w)
                % QString("#!|") % "修改成功";
        emit signalSendMsgToClient(userID, msg);
    }
    else
    {
        HouseInfo house(houseID, hotelID,houseType,price, count, area, capacity,
                        bedType ,bathroom,window, net, breakfast, media,bathroomAcc);
        if (ExecSQL::addNewHouseInfo(house))
        {
            msg = QString(CMD_SubmitHouse_w)
                    % QString("#!|") % "添加成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else
        {
            msg = QString(CMD_SubmitHouse_w)
                    % QString("#?|") % "添加错误，未知";
            emit signalSendMsgToClient(userID, msg);
        }
    }
}

///  接收到房间类型的图片
void MsgProcess::parseSubmitHouseImage(const QString msg, const QImage& image)
{
    QStringList valueList = msg.split("|");
    QString userID = valueList.at(0);
    QString houseID = valueList.at(1);
    QString msgSend = QString(CMD_SubmitHouseImage_q)
            % QString("#!|成功");

    emit signalSendMsgToClient(userID,msgSend);
    emit signalSaveHouseImage(houseID,image);
    emit signalShowImage(image);
}
///  接收到酒店的图片
void MsgProcess::parseSubmitHotelImage(const QString msg, const QImage& image)
{
    QStringList valueList = msg.split("|");
    QString userID = valueList.at(0);
    QString hotelID = valueList.at(1);
    int totalCount = valueList.at(2).toInt();
    int currentIndex = valueList.at(3).toInt();
    qDebug() << "totalCount = " << totalCount << "currentIndex = " << currentIndex;
    QString msgSend = QString(CMD_SubmitHotelImage_Q)
            % QString("#!|成功");
    emit signalSendMsgToClient(userID,msgSend);
    emit signalSaveHotelImage(hotelID,image);
    emit signalShowImage(image);

    if (totalCount == currentIndex+1)
    {
         emit signalUploadPicSuccessed();
    }
}

void MsgProcess::parseGainOrderManageList(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    enum USER_ROLE role = USER_All;
    QString hotelID;
    QString index;
    if (GlobalVars::g_userInfoMap.contains(userID))
    {
        UserInfoList::iterator iter = GlobalVars::g_userInfoMap[userID];
        if (iter->getRole().toInt() == USER_Business)
        {
            role = USER_Business;
            hotelID = list.at(1);
            index = list.at(2);
        }
        else
        {
            role = USER_Worker;
            index = list.at(1);
        }
    }

    if (index == "0")                                                       /// 获取整个订单的个数、列表
    {
        if (role == USER_Business)
        {
            ExecSQL::searchReserveInfosForHotel(hotelID);
        }
        else
        {
            ExecSQL::searchAllReserveInfos();
        }
        m_reserveInedx = 0;
        if (GlobalVars::g_reserveInfoList->size() == 0)
        {
            msg = QString(CMD_OrderManageList_x)
                    % QString("#?|") % "您还没有订单哦";
            emit signalSendMsgToClient(userID, msg);
        }else                                                                                 /// 将店面的列表逐个发送 --- 请求一次发一次
        {
            sendOrderManageListOneByOne(userID);
        }
    }
    else
    {
        sendOrderManageListOneByOne(userID);
    }
}
void MsgProcess::sendOrderManageListOneByOne(QString& userID)
{
    if (m_reserveInedx < GlobalVars::g_reserveInfoList->size())
    {
        /// !/?  reserveID  hotelID ReserveTime HouseCount hotelType Pay CheckInName
        ///  CheckInTel HouseType State
        QString reserveID = GlobalVars::g_reserveInfoList->at(m_reserveInedx).getReserve();
        if (GlobalVars::g_reserveInfoMap.contains(reserveID))
        {
            ReserveInfoList::iterator iter =  GlobalVars::g_reserveInfoMap[reserveID];
            QString msg = QString(CMD_OrderManageList_x)
                    % QString("#!|") % reserveID
                    % "|" % iter->getHotel()
                    % "|" % iter->getReserveTime()
                    % "|" % iter->getHouseType()
                    % "|" % QString::number(iter->getHouseCount())
                    % "|" % QString::number(iter->getPayment())
                    % "|" % iter->getCheckInName()
                    % "|" % iter->getCheckInTel()
                    % "|" % iter->getCheckInTime()
                    % "|" % iter->getCheckOutTime()
                    % "|" % iter->getArrivalTime()
                    % "|" % iter->getState();

            m_reserveInedx++;
            emit signalSendMsgToClient(userID, msg);
        }
    }
    else
    {
        QString msg = QString(CMD_OrderManageList_x)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendMsgToClient(userID, msg);
    }
}
void MsgProcess::parseModifyOrderState(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString reserveID = list.at(1);
    QString state = list.at(2);

    ExecSQL::searchReserveInfosForID(reserveID);
    if (GlobalVars::g_reserveInfoList->size() == 0)
    {
        msg = QString(CMD_ModifyOrderState_u)
                % QString("#?|") % "没有订单";
        emit signalSendMsgToClient(userID, msg);
    }
    else
    {
        if (ExecSQL::modifyReserveInfoForState(reserveID,state))
        {
            msg = QString(CMD_ModifyOrderState_u)
                    % QString("#!|") % "成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else{
            msg = QString(CMD_ModifyOrderState_u)
                    % QString("#?|") % "未知错误";
            emit signalSendMsgToClient(userID, msg);
        }
    }
}
void MsgProcess::parseSubmitBusComment(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString commentID = list.at(1);
    QString comment = list.at(2);

    ExecSQL::searchAllCommentInfos();
    if (GlobalVars::g_commentInfoMap.contains(commentID))
    {
        if (ExecSQL::modifyCommentInfoForHotelComment(commentID,comment))
        {
            msg = QString(CMD_SubmitBusComment_r)
                    % QString("#!|") % "修改成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else
        {
            msg = QString(CMD_SubmitBusComment_r)
                    % QString("#?|") % "未知错误，没有修改成功";
            emit signalSendMsgToClient(userID, msg);
        }
    }
    else
    {
        msg = QString(CMD_SubmitBusComment_r)
                % QString("#?|") % "未知错误，没有该订单";
        emit signalSendMsgToClient(userID, msg);
    }
}


void MsgProcess::parseGainUserCertList(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);

    if (list.at(1) == "0")                                                       /// 获取整个id审核的个数、列表
    {
        ExecSQL::searchUserInfoForCertState("正在审核");
        m_userInedx = 0;
        if (GlobalVars::g_userInfoList->size() == 0)
        {
            msg = QString(CMD_UserCert_O)
                    % QString("#?|") % "没有用户提出审核";
            emit signalSendMsgToClient(userID, msg);
        }else                                                                                 /// 将店面的列表逐个发送 --- 请求一次发一次
        {
            sendUserCertListOneByOne(userID);
        }
    }
    else
    {
        sendUserCertListOneByOne(userID);
    }
}
void MsgProcess::sendUserCertListOneByOne(QString& userID)
{
    if (m_userInedx < GlobalVars::g_userInfoList->size())
    {
        /// !/?  reserveID  hotelID ReserveTime HouseCount hotelType Pay CheckInName
        ///  CheckInTel HouseType State
        QString id = GlobalVars::g_userInfoList->at(m_userInedx).getNumber();
        if (GlobalVars::g_userInfoMap.contains(id))
        {
            UserInfoList::iterator iter =  GlobalVars::g_userInfoMap[id];
            QString msg = QString(CMD_UserCert_O)
                    % QString("#!|") % id
                    % "|" % iter->getName()
                    % "|" % iter->getSex()
                    % "|" % iter->getRealName();

            m_userInedx++;
            emit signalSendMsgToClient(userID, msg);
        }
    }
    else
    {
        QString msg = QString(CMD_UserCert_O)
                % QString("#?|") % "没有下一条记录" ;
        emit signalSendMsgToClient(userID, msg);
    }
}
void MsgProcess::parseGainUserCertImage(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString index = list.at(1);

    if (index == "0")                                            /// 获取整个认证的个数、列表
    {
        m_userImageInedx = 0;
        m_userImageCount = 0;          /// 已经发送完成图片的认证人员个数
        if (GlobalVars::g_userInfoList->size() == 0)
        {
            msg = QString(CMD_UserCertImage_K)
                    % QString("#?|") % "暂时还没有认证的";
            emit signalSendImageToClient(userID, msg,"");
        }else
        {
            sendUserCertImageOneByOne(userID);
        }
    }
    else if (index == "1")          /// 同一个认证用户的其他图片
    {
        m_userImageInedx++;
        sendUserCertImageOneByOne(userID);
    }
    else                                         /// 下一个认证用户的图片
    {
        m_userImageCount++;
        m_userImageInedx = 0;
        sendUserCertImageOneByOne(userID);
    }
}
void MsgProcess::sendUserCertImageOneByOne(QString& userID)
{
    if (m_userImageCount < GlobalVars::g_userInfoList->size())
    {
            /// 获取数据库中的头像及认证图片的路径
            /// 将路径的个数放入到glovar的userImageCount
            /// 利用userImageIndex逐个发送
            /// 一个认证人员完成后userImageIndex归零
        QString certUserID = GlobalVars::g_userInfoList->at(m_userImageCount).getNumber();
        if (GlobalVars::g_userInfoMap.contains(certUserID))
        {
            UserInfoList::iterator iter =  GlobalVars::g_userInfoMap[certUserID];
                if (m_userImageInedx == 0)
                {
                    QString msg = QString(CMD_UserCertImage_K)
                    % QString("#!|") % certUserID;
                    qDebug() << "headPic" << iter->getHeadPic();
                    emit signalSendImageToClient(userID, msg,iter->getHeadPic());
                }
                else
                {
                    QString message = QString(CMD_UserCertImage_K) % QString("#!|") % certUserID;
                    QStringList pathList = iter->getCertPath().split("#");                             /// 评论的所有图片

                    if (m_userImageInedx < pathList.size())
                    {
                        if (pathList.size() < 2)/// 数据库中数据错误 -- 导致没有图片
                        {
                            m_userImageInedx++;
                            emit signalSendImageToClient(userID, message, ":/image/errorImage/noPic.jpg");// 无图片 -- 图片损坏
                        }
                        else
                        {
                            emit signalSendImageToClient(userID, message, pathList.at(0)+"\\"+pathList.at(m_userImageInedx));
                        }
                    }
                    else
                    {
                        QString msg = QString(CMD_UserCertImage_K)
                                % QString("#?|") % "没有下一条记录" ;
                        emit signalSendImageToClient(userID, msg,"");
                    }
                }
        }
    }
    else
    {
        QString msg = QString(CMD_UserCertImage_K)
                % QString("#?|") % "没有更多记录" ;
        emit signalSendImageToClient(userID, msg,"");
    }
}
void MsgProcess::parseUserCertResult(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString modifyUserID = list.at(1);

    if (list.at(2) == "0")              ///不通过
    {
        if (ExecSQL::modifyUserInfoForCertState(modifyUserID,""))
        {
            msg = QString(CMD_UserCertResult_J)
                    % QString("#!|") % "成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else
        {
            msg = QString(CMD_UserCertResult_J)
                    % QString("#?|") % "设置不通过认证错误";
            emit signalSendMsgToClient(userID, msg);
        }
    }
    else                                        ///通过
    {
        if (ExecSQL::modifyUserInfoForCertState(modifyUserID,"已认证"))
        {
            msg = QString(CMD_UserCertResult_J)
                    % QString("#!|") % "成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else
        {
            msg = QString(CMD_UserCertResult_J)
                    % QString("#?|") % "设置通过认证错误";
            emit signalSendMsgToClient(userID, msg);
        }
    }
}

void MsgProcess::parseHotelCertResult(QString msg)
{
    QStringList list = msg.split("|");
    QString userID = list.at(0);
    QString hotelID = list.at(1);

    if (list.at(2) == "0")              ///
    {
        if (ExecSQL::deleteHotelInfo(hotelID))
        {
            msg = QString(CMD_HotelCertResult_K)
                    % QString("#!|") % "成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else
        {
            msg = QString(CMD_HotelCertResult_K)
                    % QString("#?|") % "删除错误";
            emit signalSendMsgToClient(userID, msg);
        }
    }
    else
    {
        if (ExecSQL::modifyHotelInfoForState(hotelID,"已审核"))
        {
            msg = QString(CMD_HotelCertResult_K)
                    % QString("#!|") % "成功";
            emit signalSendMsgToClient(userID, msg);
        }
        else
        {
            msg = QString(CMD_HotelCertResult_K)
                    % QString("#?|") % "修改错误";
            emit signalSendMsgToClient(userID, msg);
        }
    }
}
